﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Expression.Entity;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.Database.Service;

namespace T.FAS.Runtime.Expression.Dev.Dao
{
    public class ExprMetaDataDao : DaoService<ExprMetaData>
    {
        public ExprMetaDataDao() :
           base()
        {
            DBName = "TFAS";
        }

        public override string TableName => "FAS_ExprMetaData";
        public override string IDColumnName => "ID"; 
        public override Dictionary<string, object> GetDataMapping(ExprMetaData data)
        {
            var datas = base.GetDataMapping(data);
            datas.Remove("IsDynamic");
            datas.Add("IsDynamic", (bool)data.IsDynamic);
            return datas;
        }
        public override ExprMetaData ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            var myCol = new Dictionary<string, PropertyInfo>(base.Columns);
            myCol.Remove("IsDynamic");
            var data = base.ConvertToObject(myCol, row);
            if (row["IsDynamic"] != DBNull.Value)
                data.IsDynamic = Convert.ToBoolean(row["IsDynamic"]);
            return data;
        }
        public List<ExprMetaData> GetExprMetaDataList()
        {
            var result = new List<ExprMetaData>();
            List<object> objects = base.GetObjectsByFilter("1=1");
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as ExprMetaData));
            }
            return result;
        }
    }
}
